package net.hn.hnms.biz.energy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.hn.hnms.biz.energy.domain.WaterSupplyCompany;
import net.hn.hnms.biz.energy.vo.MonthValue;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface StatisticsMapper extends BaseMapper<WaterSupplyCompany> {

    /**
     * 按月份统计水
     *
     */
    @Select("<script> select \"sum\"(water_consumption) waterconsumption from water_settlement where mine_code in (#{mineCode}) and del_flag = '0' and to_char(meter_date,'YYYYMM') = to_char((select now() - interval '1 month'),'YYYYMM')  " +
            "  </script>")
    Map<String,Object> getWaterConsumptionMonth(@Param("mineCode") String mineCode);

    /**
     * 按月份统计电
     *
     */
    @Select("<script> select \"sum\"(settle_electric_consumption) settleelectricconsumption from electricity_settlement where mine_code in (#{mineCode}) and del_flag = '0' and to_char(settle_date,'YYYYMM') = to_char((select now() - interval '1 month'),'YYYYMM')  " +
            "  </script>")
    Map<String,Object> getSettleElectricConsumptionMonth(@Param("mineCode") String mineCode);

    /**
     * 按年份统计水
     *
     */
    @Select("<script> select \"sum\"(water_consumption) waterconsumption from water_settlement where mine_code in (#{mineCode}) and del_flag = '0' and to_char(meter_date,'YYYY') = to_char((SELECT now()::timestamp),'YYYY')   " +
            "  </script>")
    Map<String,Object> getWaterConsumptionYear(@Param("mineCode") String mineCode);

    /**
     * 按年份统计电
     *
     */
    @Select("<script> select \"sum\"(settle_electric_consumption) settleelectricconsumption from electricity_settlement where mine_code in (#{mineCode}) and del_flag = '0' and to_char(settle_date,'YYYY') = to_char((SELECT now()::timestamp),'YYYY')   " +
            "  </script>")
    Map<String,Object> getSettleElectricConsumptionYear(@Param("mineCode") String mineCode);


    List<Map<String,String>> costOfPlace(@Param("beginDate") Date startDate, @Param("endDate") Date endDate,@Param("mineCode") String mineCode);

    List<MonthValue> costWaterByYear(@Param("beginDate") Date startDate, @Param("endDate") Date endDate, @Param("mineCode") String mineCode);

    List<String> waterPlaceList(@Param("mineCode") String mineCode);




}
